package src.main.CreationalPatterns.Prototype;

import java.util.ArrayList;
import java.util.List;

// 具体原型类：哥布林
public class Goblin implements GameCharacter {

    // 名称
    private String name;
    // 技能
    private List<String> skills; // 引用类型属性（需深拷贝）

    public Goblin(String name, List<String> skills) {
        this.name = name;
        this.skills = new ArrayList<>(skills);
    }

    @Override
    public Goblin clone() {
        try {
            Goblin cloned = (Goblin) super.clone();
            cloned.skills = new ArrayList<>(this.skills);// 深拷贝技能列表
            return cloned;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }

    public void setName(String name) {
        this.name = name;
    }

    public void addSkill(String skill) {
        this.skills.add(skill);
    }

    @Override
    public void display() {
        System.out.println("角色: " + name + " | 技能: " + skills);
    }
}
